/* 34. 在排序数组中查找元素的第一个和最后一个位置 */
/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
var searchRange = function (nums, target) {
	const len = nums.length
	if (
		!len ||
		nums[0] > target ||
		nums[len - 1] < target ||
		!nums.includes(target)
	)
		return [-1, -1]
	let start = 0,
		end = len - 1
	while (start <= end) {
		const mid = start + ((end - start) >> 1)
		if (nums[mid] >= target) {
			end = mid - 1
		} else {
			start = mid + 1
		}
	}
	end = start
	while (end < len) {
		if (nums[end] === target && nums[end + 1] === target) {
			end++
		} else break
	}
	return [start, end]
}
const ans = searchRange([0, 0, 0, 1, 2, 3], 0)
console.log('searchRange :>>', ans)
